<?php

class UrlVars 
{
	private static $vars = null;
	private static $controller = null;
	private static $action;
	private static $subactions = array();

	private function __construct()
	{
 		self::$vars = explode("/", str_replace( $_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI'] ) );
 		

 		if ( $_SERVER['SCRIPT_NAME'] == $_SERVER['REQUEST_URI'] || self::$vars == explode("/", $_SERVER['REQUEST_URI'] ) )
 			self::$controller = $GLOBALS['CFG']->config['defaultController'];
 		else
 		{
 			foreach( self::$vars as $key => $val )
	 		{
	 			if ( $key == 0 )
	 				continue;
	 			if ( $key == 1 )
		 			self::$controller = $val;
		 		elseif ( $key == 2 )
		 			self::$action = $val;
		 		else
		 			self::$subactions[] = $val;
	 		}
 		}
 		self::$vars = null;
	}

	public static function getController()
	{
		self::singleton();
		return self::$controller;
	}

	public static function getAction()
	{
		self::singleton();
		return self::$action;
	}

	public static function getSubActions()
	{
		self::singleton();
		return self::$controller;
	}

	private function singleton()
	{
		if ( self::$controller == null )
			new UrlVars();
	}

}

?>